<?php
/**
 * rakuten订单 (乐天)
 * (rakuten-model)
 */

namespace App\Models\Rakuten;

use App\Models\Basics\SysPlat;
use App\Models\Basics\SysPlatCountry;
use App\Models\CustomerDelivery\CustomerDelivery;
use App\Models\CustomerDelivery\CustomerDeliveryDetail;
use App\Models\CustomerDelivery\CustomerOrder;
use App\Models\CustomerDelivery\CustomerOrderDetails;
use App\Models\Product\ProductRakutenSku;
use App\Models\Sys\Logs;
use App\Util\SerialNo;
use Illuminate\Database\Eloquent\Model;

class RakutenOrder extends Model{

    protected $connection = 'mysql_rakuten';

    protected $table = 'rakuten_orders';

    protected $guarded  = [];

    /**
     * rakuten同步erp订单状态
     * @var string[]
     */
    const SYNC_NO = 1; //未同步
    const SYNC_YES = 2; //已同步
    const SYNC_ERROR = 3; //同步异常
    public static $_erpSync = [
        1 => '未同步',
        2 => '已同步',
        3 => '同步异常',
    ];

    /**
     * rakuten同步海外仓订单状态
     * @var string[]
     */
    const OVERSEAS_SYNC_NO = 1; //未同步
    const OVERSEAS_SYNC_YES = 2; //已同步
    const OVERSEAS_SYNC_ERROR = 3; //同步异常
    public static $_overseasSync = [
        1 => '未同步',
        2 => '已同步',
        3 => '同步异常',
    ];

    /**
     * 关联明细
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
     */
    public function rakuten_orders_items(){
        return $this->hasMany(RakutenOrderItem::class, 'order_id', 'order_id');
    }

    /**
     * 关联物流
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
     */
    public function rakuten_orders_shipping(){
        return $this->hasMany(RakutenOrderShipping::class, 'order_id', 'order_id');
    }

    /**
     * 关联订单地址
     * @return \Illuminate\Database\Eloquent\Relations\HasOne
     */
    public function rakuten_orders_address(){
        return $this->hasOne(RakutenOrderAddress::class, 'order_id', 'order_id');
    }

}
